<?php
//	Original Framework http://theundersigned.net/2006/06/wordpress-how-to-theme-options/ 
//	Updated and added additional options by Jeremy Clark
//	http://clarktech.no-ip.com/
//	Updated and added additional options by Mike Pippin -9/11/2009
//	http://split-visionz.net/2009/wordpress-theme-options-framework-updated/



$themename = "Zen Comet";
$shortname = "fp";
$options = array (
	// array(	"name" => "Color scheme",
	// 		"desc" => "Select color scheme",
	// 		"id" => $shortname."_color",
	// 		"type" => "select",
	// 		"std" => "Grey",
	// 		"options" => array("Grey","Red","Yellow","Green","Teal","Blue","Purple")
	// ),

	array(	"name" => "Font",
			"desc" => "Select general font",
			"id" => $shortname."_font",
			"type" => "select",
			"std" => "Georgia",
			"options" => array("Verdana","Tahoma","Helvetica","Trebuchet","Georgia")
	),

	array(	"name" => "Font size",
			"desc" => "Select font size",
			"id" => $shortname."_fontsize",
			"type" => "select",
			"std" => "13px",
			"options" => array("15px","14px","13px","12px","11px")
	),

	array(	"name" => "Sidebar layout",
			"desc" => "Select layout of the sidebar",
			"id" => $shortname."_sidebar",
			"type" => "select",
			"std" => "Right",
			"options" => array("Right","Left","Left and Right","Hidden")
	),

	// array(	"name" => "Logo",
	// 		"desc" => "URL to an image (replaces title & tagline)",
	// 		"id" => $shortname."_logo",
	// 		"std" => "",
	// 		"type" => "text"
	// ),

	// array(	"name" => "Logo position",
	// 		"desc" => "Position of the logo",
	// 		"id" => $shortname."_logopos",
	// 		"type" => "select",
	// 		"std" => "Left",
	// 		"options" => array("Left","Center","Right")
	// ),

	// array(	"name" => "Background image",
	// 		"desc" => "URL to a background image",
	// 		"id" => $shortname."_bgimg",
	// 		"std" => "",
	// 		"type" => "text"
	// ),

	array(	"name" => "Subscribe title",
			"desc" => "Title for the subscribe link (i.e. \"Subscribe\")",
			"id" => $shortname."_subscribe",
			"std" => "Subscribe",
			"type" => "text"
	),

	array(	"name" => "Feedburner",
			"desc" => "Alternative <a href=\"http://feedburner.google.com\" target=\"_blank\">Feedburner</a> URL for the \"Subscribe\" link",
			"id" => $shortname."_feedburner",
			"std" => "",
			"type" => "text"
	),

	array(	"name" => "Front Page post type",
			"desc" => "Displays the full posts or the <a href='http://codex.wordpress.org/Excerpt' target='_blank'>excerpt</a>",
			"id" => $shortname."_typeFront",
			"type" => "select",
			"std" => "Full",
			"options" => array("Full","Excerpt")
	),

	array(	"name" => "Archive Pages post type",
			"desc" => "Displays the full posts or the <a href='http://codex.wordpress.org/Excerpt' target='_blank'>excerpt</a>",
			"id" => $shortname."_typeArchive",
			"type" => "select",
			"std" => "Excerpt",
			"options" => array("Full","Excerpt")
	),

	array(	"name" => "Next/previous post links",
			"desc" => "Display links to next/previous posts on single post pages",
			"id" => $shortname."_postnav",
			"type" => "select",
			"std" => "Yes",
			"options" => array("Yes","No")
	),

	// array(	"name" => "Menu bar",
	// 		"desc" => "Display the menu bar at the top",
	// 		"id" => $shortname."_menu",
	// 		"type" => "select",
	// 		"std" => "Yes",
	// 		"options" => array("Yes","No")
	// ),

	array(	"name" => "Home link",
			"desc" => "Display \"Home\" in the menu",
			"id" => $shortname."_home",
			"type" => "select",
			"std" => "Yes",
			"options" => array("Yes","No")
	),

	array(	"name" => "Post author",
			"desc" => "Display the author of each post",
			"id" => $shortname."_post_author",
			"type" => "select",
			"std" => "Yes",
			"options" => array("Yes","No")
	),

	// array(	"name" => "Post separator",
	// 		"desc" => "Display the grey sign between posts",
	// 		"id" => $shortname."_separator",
	// 		"type" => "select",
	// 		"std" => "Yes",
	// 		"options" => array("Yes","No")
	// ),

	array(  "name" => "Footer",
	    "desc" => "Text to appear in the footer",
            "id" => $shortname."_footer",
            "std" => "",
            "type" => "textarea"
	),

	array(  "name" => "Custom CSS",
	    "desc" => "Place any custom <a href=\"http://www.w3schools.com/css/\" target=\"_blank\">CSS</a> you have here",
            "id" => $shortname."_customcss",
            "std" => "",
            "type" => "textarea"
	)
);

function mytheme_add_admin() {

    global $themename, $shortname, $options;

    if ( $_GET['page'] == basename(__FILE__) ) {
    
        if ( 'save' == $_REQUEST['action'] ) {

                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }

                foreach ($options as $value) {
					if(($value['type'] === "checkbox" or $value['type'] === "multiselect" ) and is_array($_REQUEST[ $value['id'] ])){$_REQUEST[ $value['id'] ]=implode(',',$_REQUEST[ $value['id'] ]);}
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }

                header("Location: themes.php?page=controlpanel.php&saved=true");
                die;

        } else if( 'reset' == $_REQUEST['action'] ) {

            foreach ($options as $value) {
                delete_option( $value['id'] ); 
                update_option( $value['id'], $value['std'] );}

            header("Location: themes.php?page=controlpanel.php&reset=true");
            die;

        }
    }

    add_theme_page($themename." Options", "Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');

}

function mytheme_admin() {

    global $themename, $shortname, $options;

    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
?>
<div class="wrap">
<h2><?php echo $themename; ?> settings</h2>

<form method="post">

<table class="optiontable">

<?php foreach ($options as $value) { 
    
if ($value['type'] == "text") { ?>
  <tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>
        <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'] )); } else { echo stripslashes($value['std']); } ?>" size="40" />
    </td>
</tr>
<tr><td colspan=2><hr /></td></tr>
<?php } elseif ($value['type'] == "select") { ?>
<tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>
            <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
                <?php foreach ($value['options'] as $option) { ?>
                <option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; }?>><?php echo $option; ?></option>
                <?php } ?>
            </select>
        </td>
    </tr>
<tr><td colspan=2><hr /></td></tr>
<?php } elseif ($value['type'] == "multiselect") { ?>
<tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>		
            <select  multiple="multiple" size="3" name="<?php echo $value['id']; ?>[]" id="<?php echo $value['id']; ?>" style="height:50px;">
                <?php $ch_values=explode(',',get_settings( $value['id'] )); foreach ($value['options'] as $option) { ?>
                <option<?php if ( in_array($option,$ch_values)) { echo ' selected="selected"'; }?> value="<?php echo $option; ?>"><?php echo $option; ?></option>
                <?php } ?>
            </select>		
        </td>
    </tr>
<tr><td colspan=2><hr /></td></tr>

<?php } elseif ($value['type'] == "radio") { ?>
<tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>
		<?php foreach ($value['options'] as $option) { ?>
			<?php echo $option; ?><input name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php echo $option; ?>" <?php if ( get_settings( $value['id'] ) == $option) { echo 'checked'; } ?>/>|
		<?php } ?>
        </td>
    </tr>
<tr><td colspan=2><hr /></td></tr>
<?php } elseif ($value['type'] == "textarea") { ?>
<tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>
            <textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" cols="40" rows="5"/><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'] )); } else { echo stripslashes($value['std']); } ?></textarea>
		</td>
    </tr>
<tr><td colspan=2><hr /></td></tr>

<?php } elseif ($value['type'] == "checkbox") { ?>

    <tr valign="top"> 
        <th scope="top" style="text-align:left;"><?php echo $value['name']; ?>:</th>
	<?php if(isset($value['desc'])){?>
	</tr>
	<tr valign="top"> 
		<td style="width:50%; padding-right:10px;"><?php echo $value['desc']?></td>
	<?php } ?>
        <td>
		<?php 
		$ch_values=explode(',',get_settings( $value['id'] ));
		foreach ($value['options'] as $option) { 
		echo $option; ?><input name="<?php echo $value['id']; ?>[]" type="<?php echo $value['type']; ?>" value="<?php echo $option; ?>" <?php if ( in_array($option,$ch_values)) { echo 'checked'; } ?>/>|
		<?php } ?>

        </td>
    </tr>
<tr><td colspan=2><hr /></td></tr>
<?php } ?>
<?php 
}
?>
</table>
<p class="submit">
<input name="save" type="submit" value="Save changes" />    
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
<em>Framework by <a href="http://clarktech.no-ip.com/" title="Jeremy Clark">Jeremy Clark</a></em>
<?php
}
add_action('admin_menu', 'mytheme_add_admin'); ?>
